package com.example.interceptor;

public class Page {
    protected int totalNumber;//当前表中总条目数量
    protected int currentPage;//当前页的位置
    protected int totalPage;//总页数
    protected int pageSize;//页面大小
    protected int startIndex;//检索的起始位置
    protected int totalSelect;//检索的总数目
    //...省略其他set，get方法
    public void setTotalNumber(int totalNumber) {
        this.totalNumber = totalNumber;
        this.count();
    }
    //...省略其他set，get方法


    public int getTotalNumber() {
        return totalNumber;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getTotalSelect() {
        return totalSelect;
    }

    public void setTotalSelect(int totalSelect) {
        this.totalSelect = totalSelect;
    }

    public Page() {
    }

    public Page(int currentPage, int pageSize) {
        super();
        this.currentPage = currentPage;
        this.pageSize = pageSize;
    }
    public void count(){
        int totalPageTemp = this.totalNumber/this.pageSize;
        int plus = (this.totalNumber%this.pageSize)==0?0:1;
        totalPageTemp = totalPageTemp+plus;
        if(totalPageTemp<=0){
            totalPageTemp=1;
        }
        this.totalPage = totalPageTemp;//总页数

        if(this.totalPage<this.currentPage){
            this.currentPage = this.totalPage;
        }
        if(this.currentPage<1){
            this.currentPage=1;
        }
        this.startIndex = (this.currentPage-1)*this.pageSize;//起始位置等于之前所有页面输乘以页面大小
        this.totalSelect = this.pageSize;//检索数量等于页面大小
    }

    @Override
    public String toString() {
        return "Page{" +
                "totalNumber=" + totalNumber +
                ", currentPage=" + currentPage +
                ", totalPage=" + totalPage +
                ", pageSize=" + pageSize +
                ", startIndex=" + startIndex +
                ", totalSelect=" + totalSelect +
                '}';
    }
}
